﻿using DotNetty.Transport.Channels;
using DotNetty.Transport.Channels.Groups;
using iTool.Common.Models;

namespace iTool.Core.EventTriggered
{
    /// <summary>
    /// 触发事件
    /// </summary>
    public interface IWebSocketEventTriggered<TMessage>
        where TMessage : AbstractMessage
    {
        /// <summary>
        /// 新连接
        /// </summary>
        /// <param name="context"></param>
        Task OnConnect(IChannelHandlerContext context);

        /// <summary>
        /// 关闭连接
        /// </summary>
        /// <param name="context"></param>
        Task OnClose(IChannelHandlerContext context);

        Task OnClose(IChannel context);

        /// <summary>
        /// 收到消息
        /// </summary>
        /// <param name="context"></param>
        /// <param name="message"></param>
        Task OnMessage(IChannelHandlerContext context, TMessage message);

        /// <summary>
        /// 需要推送消息
        /// </summary>
        /// <param name="group"></param>
        /// <param name="messageOfString"></param>
        Task OnSendMessage(IChannelGroup group, string messageOfString);

        /// <summary>
        /// 发送错误
        /// </summary>
        /// <param name="context"></param>
        Task OnError(IChannelHandlerContext context, OnExceptionContext exceptionContext);

        /// <summary>
        /// 用户事件
        /// </summary>
        /// <param name="context"></param>
        Task UserEventTriggered(IChannelHandlerContext context, object evt);
    }
}
